package net.maku.module.util;

import java.time.YearMonth;
import java.time.format.DateTimeFormatter;

public class DateUtils {
    public static String getEndDateWithLastDay(String yearMonth) {
        YearMonth ym = YearMonth.parse(yearMonth, DateTimeFormatter.ofPattern("yyyy-MM"));
        int lastDay = ym.lengthOfMonth();
        return yearMonth + "-" + lastDay;
    }

    // 使用示例
    public static void main(String[] args) {
        System.out.println(getEndDateWithLastDay("2023-02")); // 2023-02-28
        System.out.println(getEndDateWithLastDay("2023-04")); // 2023-04-30
        System.out.println(getEndDateWithLastDay("2020-02")); // 2020-02-29 (闰年)
    }
}
